package com.servlet.model.base;

import java.io.Serializable;
import java.sql.Date;

/**
 * Expérience Professionnelle dans la base de donnée
 * Chaque utilisateur peut avoir plusieurs expériences professionnelles différentes
 * @author Jing Jing
 */
public class Experience implements Serializable {
	private String email;
	private String enterprise;
	private Date date_begin;
	private Date date_end;
	private String post;
	private Sector activity_domain;
	private String description;
	private Area area;

	private boolean is_modified_enterprise;
	private boolean is_modified_date_begin;
	private boolean is_modified_date_end;
	private boolean is_modified_post;
	private boolean is_modified_activity_domain;
	private boolean is_modified_descriptionn;
	private boolean is_modified_area;

	public Experience() {
		email = null;
		enterprise = null;
		date_begin = null;
		date_end = null;
		post = null;
		activity_domain = null;
		description = null;
		area = null;
		is_modified_enterprise = false;
		is_modified_date_begin = false;
		is_modified_date_end = false;
		is_modified_post = false;
		is_modified_activity_domain = false;
		is_modified_descriptionn = false;
		is_modified_area = false;
	}

	public Experience(String email, String enterprise, Date date_begin,
			Date date_end, String post, Sector activity_domain,
			String description, Area area) {
		this.email = email;
		this.enterprise = enterprise;
		this.date_begin = date_begin;
		this.date_end = date_end;
		this.post = post;
		this.activity_domain = activity_domain;
		this.description = description;
		this.area = area;
		is_modified_enterprise = false;
		is_modified_date_begin = false;
		is_modified_date_end = false;
		is_modified_post = false;
		is_modified_activity_domain = false;
		is_modified_descriptionn = false;
		is_modified_area = false;
	}

	public String getEmail() {
		return email;
	}

	public String getEnterprise() {
		return enterprise;
	}

	public Date getDateBegin() {
		return date_begin;
	}

	public Date getDateEnd() {
		return date_end;
	}

	public String getPost() {
		return post;
	}

	public Sector getActivityDomain() {
		return activity_domain;
	}

	public String getDescription() {
		return description;
	}

	public Area getArea() {
		return area;
	}

	public boolean getIs_modified_enterprise() {
		return is_modified_enterprise;
	}

	public boolean getIs_modified_area() {
		return is_modified_area;
	}

	public boolean getIs_modified_post() {
		return is_modified_post;
	}

	public boolean getIs_modified_activity_domain() {
		return is_modified_activity_domain;
	}

	public boolean getIs_modified_descriptionn() {
		return is_modified_descriptionn;
	}

	public boolean getIs_modified_date_begin() {
		return is_modified_date_begin;
	}

	public boolean getIs_modified_date_end() {
		return is_modified_date_end;
	}

	public void setIs_modified_enterprise(boolean is_modified_enterprise) {
		this.is_modified_enterprise = is_modified_enterprise;
	}

	public void setIs_modified_area(boolean is_modified_area) {
		this.is_modified_area = is_modified_area;
	}

	public void setIs_modified_post(boolean is_modified_post) {
		this.is_modified_post = is_modified_post;
	}

	public void setIs_modified_activity_domain(
			boolean is_modified_activity_domain) {
		this.is_modified_activity_domain = is_modified_activity_domain;
	}

	public void setIs_modified_descriptionn(boolean is_modified_descriptionn) {
		this.is_modified_descriptionn = is_modified_descriptionn;
	}

	public void setIs_modified_date_begin(boolean is_modified_date_begin) {
		this.is_modified_date_begin = is_modified_date_begin;
	}

	public void setIs_modified_date_end(boolean is_modified_date_end) {
		this.is_modified_date_end = is_modified_date_end;
	}

	public void setEmail(String email)
	{
		this.email = email;
	}
	
	public void setEnterprise(String enterprise) {
		this.enterprise = enterprise;
		is_modified_enterprise = true;
	}

	public void setDateBegin(Date date_begin) {
		this.date_begin = date_begin;
		is_modified_date_begin = true;
	}

	public void setDateEnd(Date date_end) {
		this.date_end = date_end;
		is_modified_date_end = true;
	}

	public void setPost(String post) {
		this.post = post;
		is_modified_post = true;
	}

	public void setActivityDomain(Sector activity_domain) {
		this.activity_domain = activity_domain;
		this.is_modified_activity_domain = true;
	}

	public void setDescription(String description) {
		this.description = description;
		this.is_modified_descriptionn = true;
	}

	public void setArea(Area area) {
		this.area = area;
		this.is_modified_area = true;
	}

	public String generateInsertSQL() {
		String insertSQL = "INSERT INTO experience VALUES ('" + email + "' ,'"
				+ enterprise + "' ,'" + date_begin + "' ,'" + date_end + "'";

		if (post != null)
			insertSQL += ", '" + post + "'";
		else
			insertSQL += ",null";

		if (activity_domain != null)
			insertSQL += ", '" + activity_domain.getSectorBase() + "'";
		else
			insertSQL += ", null";

		if (description != null)
			insertSQL += ", '" + description + "'";
		else
			insertSQL += ", null";

		if (area != null )
			insertSQL += " ," + area.getHCode();
		else
			insertSQL += " , null";

		insertSQL += ")";

		return insertSQL;
	}

	public String generateDeleteSQL() {
		String deleteSQL = "DELETE FROM experience WHERE email='" + email
				+ "' AND enterprise='" + enterprise + "' AND date_begin='"
				+ date_begin + "'";
		return deleteSQL;
	}
}
